#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include "mutex.hpp"
#include "lockguard.hpp"
using namespace std;
// void func(void *args)
// {
//     string message=static_cast<const char *>(args);
//     cout<<"我是被创建的线程:"<< message <<endl;
// }
int ticket=1000;
pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;

void func(void * args)
{
    string message=static_cast<const char *>(args);
    while(true)
    {
        LockGuard lockguard(&mutex);
        if(ticket > 0)
        {
            usleep(1000);
            cout<<message<<":"<<ticket--<<endl;
        }
        else break;
    }
}
int main()
{
   Thread td1(1,func,(void*)"hellotd1");
   Thread td2(2,func,(void*)"hellotd1");
   Thread td3(3,func,(void*)"hellotd1");

   td1.run();
   td2.run();
   td3.run();

   td1.join();
   td2.join();
   td3.join();
    return 0;
}